/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servidor.rmi;

/**
 *
 * @author Daniel
 */
public class ServidorRMI implements Runnable {

    RMIservice service;
    boolean alive = true;
    Thread run;

    public ServidorRMI(RMIservice service){
        run = new Thread(this);
        this.service = service;
        run.start();
    }

    public void run() {
        int erro = 0;
        System.out.println("Arrancar serviço!!!");
        while (alive) {
            erro = service.startService();
            if (erro != 0) {
                System.out.println("Falha ligacao!!!");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ex) {
                }
                System.out.println("Tenta de Novo...!!!");
                continue;
            }
            while (erro == 0) {
                System.out.println("Servidor ligado!!!");
                synchronized (this) {
                    try {
                        this.wait();
                    } catch (InterruptedException ex) {
                    }
                }
            }
        }
    }
}
